
************************************************************************************************
* Constructing data set to "Public Health Policy At Scale.."
************************************************************************************************
* Smoking variables from birth registries
*************************************************************************************************


clear 
set more off 
set matsize 8000 
cap log close 

global rawStata "D:\Data\Workdata\707116\Stata"

cd "D:\Data\workdata\707116\SIDS_RDD"

use $rawStata\lprmfrlf1996.dta , clear

gen pnr=K_BCPR 

g 		smoker = . 
replace smoker = 0 if B_RYGER=="0" 
replace smoker = 1 if B_RYGER=="1"

drop if smoker==. 

keep pnr smoker 

tempfile t1 
save `t1'

clear all 


use $rawStata\mfr2014.dta , clear 
gen dod =1 if LEVENDE_ELLER_DOEDFOEDT == "Dødfødt"
drop if dod==1

gen f_match = !regexm(CPR_FADER,"[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]")
replace CPR_FADER = "" if CPR_FADER!="" & f_match

gen m_match = !regexm(CPR_MODER,"[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]")
replace CPR_MODER = "" if CPR_MODER !="" & m_match

gen b_match = !regexm(CPR_BARN,"[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]")
replace CPR_BARN = "" if CPR_BARN !="" & b_match

gen str12 fpnr_mfr = CPR_FADER
gen str12 mpnr_mfr = CPR_MODER
gen str12 pnr = CPR_BARN

assert foedselsdato!=.

g 		smoker = . 
replace smoker = 0 if RYGERSTATUS_MODER =="00"
replace smoker = 1 if RYGERSTATUS_MODER == "10" | RYGERSTATUS_MODER == "11" | ///
					  RYGERSTATUS_MODER == "20" | RYGERSTATUS_MODER == "21" | ///
					  RYGERSTATUS_MODER == "22" | RYGERSTATUS_MODER == "23" | ///
					  RYGERSTATUS_MODER == "29"
 
g 		smoker1 = . 
replace smoker1 = 0 if RYGERSTATUS_MODER =="00"  | RYGERSTATUS_MODER == "10" 
replace smoker1 = 1 if RYGERSTATUS_MODER == "11" | ///
					  RYGERSTATUS_MODER == "20" | RYGERSTATUS_MODER == "21" | ///
					  RYGERSTATUS_MODER == "22" | RYGERSTATUS_MODER == "23" | ///
					  RYGERSTATUS_MODER == "29"
 
drop if smoker==. | pnr==""

keep pnr smoker*

append using `t1' 
 
save "D:/Data/Workdata/707116/ChildVax/02_temp/Nov2019/smoking1991_2014.dta", replace


